#include "StdAfx.h"
#include "Floor.h"

CFloor::CFloor(size_t floorNum) : m_floorNum(floorNum), m_elevatorArrivedListener(NULL)
{
}

CFloor::~CFloor(void)
{
	if (m_elevatorArrivedListener != NULL)
		delete m_elevatorArrivedListener;

	if (m_callRequestlistener != NULL)
		delete m_callRequestlistener;
}

void CFloor::ElevatorArrived()
{
	if (m_elevatorArrivedListener != NULL)
		m_elevatorArrivedListener->LoadPassengersAtArival(m_incomingPassengers);
}

void CFloor::RegisterListeners(ILoadPassengersListener* loadPassengerslistener, ICallRequestListener* callRequestListener)
{
	m_elevatorArrivedListener = loadPassengerslistener;
	m_callRequestlistener = callRequestListener;
}

void CFloor::CallElevator(bool goingUp)
{
	if (m_callRequestlistener != NULL)
		m_callRequestlistener->OnCallRequest(new CallRequest(m_floorNum, goingUp));
}

void CFloor::AddIncomingPassengers(const PassengerCollection& incomingPassengers)
{
	m_incomingPassengers.clear();
	m_incomingPassengers.reserve(incomingPassengers.size());
	for (size_t i=0; i<incomingPassengers.size(); ++i)
		m_incomingPassengers.push_back(incomingPassengers[i]);
}